﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using TERP.HTCClient.Entities.Product;
using TERP.HTCClient.Common;
using CommonUtils;
using TERP.HTCClient.Entities.Sales;

namespace TERP.HTCClient.DbServices
{
    class ProductService:BaseService
    {
		#region DECLARATIONS
		private const string TBL_COLOR = "Mst_Color";
		private const string TBL_MODEL = "Mst_Model";
		private const string TBL_CAR_PRICE = "Mst_CarPrice";
		private const string TBL_SALES_ORDER_TYPE = "Mst_SalesOrderType";
		//
		private string _tblName;
		#endregion


        public ProductService() {  }

        public ProductService(string tblName)
        { _tblName = tblName; }


        /// <summary>
        /// Car_Model
        /// </summary>
        /// <returns></returns>
        public DataTable GetDtbFromDB() 
        {
            return this.GetMasterDataTable(_tblName);
        }

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public DataTable GetMstColor()
		{
			string strTId = SystemGlobal.Instance.GetNextTid();
			DataSet mdsFinal = null;
			//
			try
			{
				mdsFinal = _dbService.MstDataGetColor(
					_strGwUserCode,
					_strGwPassword,
					strTId,
					_strSessionId,
					"",		//list color code
					"",		//list model code
					""		//flag active list for model
					);
			}
			catch (Exception ex)
			{
				throw ex;
			}
			//
			if (CMyDataSet.HasError(mdsFinal))
			{
				throw GenServiceException(mdsFinal);
			}
			//
			return mdsFinal.Tables[TBL_COLOR];
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public DataTable GetMstSalesOrderType(){
			return this.GetMasterDataTable(TBL_SALES_ORDER_TYPE);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public DataTable GetMstCarPrice()
		{
			string strTId = SystemGlobal.Instance.GetNextTid();
			DataSet mdsFinal = null;
			//
			try
			{
				mdsFinal = _dbService.MstDataGetCarPrice(
					_strGwUserCode,
					_strGwPassword,
					strTId,
					_strSessionId,
					"",		//list spec code
					"",		//spec code pattern
					"",		//effective date from
					"",		//effective date to
					"",		//flag active list for car price
					"",		//list model code
					"",		//list standard code
					"",		//list adv code
					""		//flag active list for model
					);
			}
			catch (Exception ex)
			{
				throw ex;
			}
			//
			if (CMyDataSet.HasError(mdsFinal))
			{
				throw GenServiceException(mdsFinal);
			}
			//
			return mdsFinal.Tables[TBL_CAR_PRICE];
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public DataTable GetMstModel()
		{
			string strTId = SystemGlobal.Instance.GetNextTid();
			DataSet mdsFinal = null;
			//
			try
			{
				mdsFinal = _dbService.MstDataGetModel(
					_strGwUserCode,
					_strGwPassword,
					strTId,
					_strSessionId,
					"",		//list model code
					"",		//list model production code
					"",		//model name pattern
					""		//list flag active
					);
			}
			catch (Exception ex)
			{
				throw ex;
			}
			//
			if (CMyDataSet.HasError(mdsFinal))
			{
				throw GenServiceException(mdsFinal);
			}
			//
			return mdsFinal.Tables[TBL_MODEL];
		}
    }
}
